package forum.service;

import forum.dao.*;
import forum.model.SectionListResult;
import forum.model.Topic;
import forum.model.User;

/**
 * @author haomin
 * @date 2022/06/30 11:29
 **/
public class SectionService {
    public SectionListResult sectionListResult(User currentUser){
        SectionDao sectionDao = new SectionDao();
        SectionListResult result = new SectionListResult();

        result.currentUser = currentUser;
        if(currentUser != null){
            result.pointCount = new UserDao().selectPointCountByUid(currentUser.uID);
            result.classCount = new UserDao().selectClassCountByUid(currentUser.uID);
            result.sectionList = sectionDao.selectListByUid();
        }

        return result;
    }

    public SectionListResult sectionListResult(User currentUser, String keyword) {
        System.out.println(keyword+"00");
        new KeyDao().deleteKey();
        SectionDao sectionDao = new SectionDao();
        TopicDao topicDao = new TopicDao();
        SectionListResult result = new SectionListResult();

        result.currentUser = currentUser;
        if(currentUser != null){
            result.pointCount = new UserDao().selectPointCountByUid(currentUser.uID);
            result.classCount = new UserDao().selectClassCountByUid(currentUser.uID);
            result.sectionList = sectionDao.selectSectionListByKeyword(keyword);
            result.topicList = topicDao.selectTopicListByKeyword(keyword);
            System.out.println("99");

        }

        return result;
    }
}